<?php

// phpMyRealty 3
//
// File Name: alerts.php
// File Location : ./admin/
//
// Copyright (c)2009 phpMyRealty.com
//
// e-mail: support@phpMyRealty.com

// Include configuration file and general functions
define('PMR', 'true');
define('PMRADMIN', 'true');

include ( '.././config.php' );
include ( PATH . '/defaults.php' );

// ----------------------------------------------------------------------
// ADMIN PANEL / VIEW ALERTS

// Title tag value
$title = $lang['Alert'];

// Template header
include ( PATH . '/admin/template/header.php' );

// If logged we can start the page output
if (adminAuth($session->fetch('adminlogin'), $session->fetch('adminpassword')))
 {
  // Include navigation panel
  $session->set('navigation', '');
  include ( PATH . '/admin/navigation.php' );

  if (isset($_GET['code'])) {
   $db->query('DELETE FROM ' . ALERTS_TABLE . ' WHERE code = ' . $_GET['code']);
   echo 'ALERT REMOVED<br />';
  }

  // Fetching the configuration data from the database
  $sql = 'SELECT * FROM ' . ALERTS_TABLE;
  $r = $db->query( $sql );

  // Generating the configuration form
  echo table_header ( $lang['Alert'] );

  echo ' <table cellpadding="7" cellspacing="0" border="0" width="100%">';

  while ($f = $db->fetcharray( $r ))

   {

    $cat = explode ("#", $f['city']);
    $r11 = $db->query('SELECT category FROM ' . LOCATION1_TABLE . ' WHERE selector = "' . $cat[0] . '"');
    $f11 = $db->fetcharray($r11);

    $r22 = $db->query('SELECT subcategory FROM ' . LOCATION2_TABLE . ' WHERE catsubsel = "' . $cat[1] . '"');
    $f22 = $db->fetcharray($r22);

    $r33 = $db->query('SELECT subsubcategory FROM ' . LOCATION3_TABLE . ' WHERE catsubsubsel = "' . $cat[2] . '"');
    $f33 = $db->fetcharray($r33);

    if ($f['approved'] == 1)
    $font_color="green"; else $font_color="red";

    echo alertform ('<font color="' . $font_color . '"><b>' . $f['name'] . ' - ' . $f['email'] . '</b></font>', $lang['Alert_Type'] . ': ' . getnamebyid(TYPES_TABLE, $f['type']) . ', ' . $lang['Alert_Zip'] . ': ' . $f['zip'] . ' (' . $f11['category'] . '/' . $f22['subcategory'] . '/' . $f33['subsubcategory'] . ') <a href="' . URL . '/admin/alerts.php?code=' . $f['code'] . '">REMOVE</a>');

   }

  echo ' </table>
       '; 

  echo '<br /><br /><div align="center">Total: ' . $db->numrows($r) . ', <font color="green"><b>Green</b></font> - Approved, <font color="red"><b>Red</b></font> - Pending</div>';

  echo table_footer ();

 }

else

 {

  error ('Critical Error' , 'Please, login to access this script.');

 }

// Template footer
include ( PATH . '/admin/template/footer.php' );

?>